<template>
  <div class="container">
    <div class="common-header-wrap">
      <mt-header title="浏览历史" class="common-header">
        <mt-button slot="left" icon="back" @click="$router.go(-1)"></mt-button>
        <mt-button slot="right" @click="showAlert()">清空浏览记录</mt-button>
      </mt-header>
    </div>
    <!-- <div v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="10">
			<div class="list-wrapper" v-if="goodsbrowse_list && goodsbrowse_list.length">
				<mt-cell-swipe class="browse-list" v-for="(item, index) in goodsbrowse_list">
					<div class="info" @click="goGoods(item.goods_id)">
						<img class="image" :src="item.goods_image_url" />
						<div class="title">
							<div>{{ item.goods_name }}</div>

							<div>{{ item.goodsbrowse_time_date }}</div>
						</div>
					</div>
				</mt-cell-swipe>
			</div>
			<empty-record v-else-if="goodsbrowse_list && !goodsbrowse_list.length"></empty-record>
    </div>-->

    <div class="goodslist-body show-goods-list">
      <!-- 无限加载滚动列表 -->
      <div
        class="flex-wrapper"
        v-infinite-scroll="loadMore"
        infinite-scroll-disabled="loading"
        infinite-scroll-distance="10"
      >
        <div
          class="ui-product-body"
          v-if="goodsbrowse_list && goodsbrowse_list.length"
          v-for="(item, index) in goodsbrowse_list"
          v-bind:key="index"
        >
          <div class="list" v-on:click="goGoods(item.goods_id)">
            <div class="ui-image-wrapper">
              <img class="product-img" v-lazy="item.goods_image_url" />
            </div>
            <div class="flex-right">
              <div class="product-header">
                <h3
                  class="title clear-bottom"
                  style="-webkit-box-orient:vertical"
                >{{ item.goods_name }}</h3>
              </div>
              <div class="storeUser">{{ item.store_name}}</div>
              <div class="p-info">
                <span class="platform_store_wrapper">
                  <span class="platform_store">¥{{ item.goods_promotion_price }}</span>
                </span>
                <span class="goods_salenum">销量:{{ item.goods_salenum * 1 + item.v_salenum * 1}}</span>
              </div>
              <div class="time">{{ item.goodsbrowse_time_date }}</div>
              <!-- <div class="add-cart">
                <i class="iconfont">&#xe681;</i>
              </div>-->
            </div>
          </div>
        </div>
        <empty-record v-if="goodsbrowse_list.length <= 0 && !isMore"></empty-record>
      </div>
    </div>

    <div class="simulationAlert" v-if="isShow">
      <div class="title">提示</div>
      <div class="text">确定清空浏览记录?</div>
      <div class="btn">
        <button class="btnLeft" @click="cancel">取消</button>
        <button class="btnRight" @click="clearallBrowse">确定</button>
      </div>
    </div>
    <div class="baffle" v-if="isShow"></div>
  </div>
</template>

<script>
import { getBrowseList, clearallBrowse } from "../../../api/memberBrowse";
import { Toast, MessageBox, Indicator } from "mint-ui";
import EmptyRecord from "../../../components/EmptyRecord";

export default {
  components: {
    EmptyRecord,
  },
  data() {
    return {
      isShow: false,
      params: { page: 0, per_page: 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      goodsbrowse_list: false,
    };
  },
  created() {
    this.params = {
      page: 0,
      per_page: 10
    }
  },
  methods: {
    goDetail() {},
    cancel() {
      this.isShow = false;
    },
    showAlert() {
      this.isShow = true;
    },
    // 清空浏览记录
    clearallBrowse() {
      this.isShow = false;
      clearallBrowse(this.params)
        .then((res) => {
          this.goodsbrowse_list = false;
        })
        .catch(function (error) {
          Toast(error.message);
        });
    },
    goBack() {
      this.$router.go(-1);
    },
    isArray(arr) {
      return Object.prototype.toString.call(arr) === "[object Array]";
    },
    loadMore() {
      this.loading = true;
      this.params.page = ++this.params.page;
      if (this.isMore) {
        this.loading = false;
        this.getBrowseList(true);
      }
    },

    getBrowseList() {
      Indicator.open();
      getBrowseList(this.params)
        .then((res) => {
          Indicator.close();
          if (res.code == "10000") {
            if (this.goodsbrowse_list && this.goodsbrowse_list.length) {
              const store_list = res.result.goodsbrowse_list;
              if (this.isArray(store_list)) {
                this.goodsbrowse_list.push(...store_list);
              } else {
                for (let key in store_list) {
                  this.goodsbrowse_list.push(store_list[key]);
                }
              }
            } else {
              this.goodsbrowse_list = res.result.goodsbrowse_list;
            }
            console.log(this.goodsbrowse_list);
            if (res.result.hasmore) {
              this.isMore = true;
            } else {
              this.isMore = false;
            }
          }
        })
        .catch((e) => {});
    },
    goGoods(id) {
      this.$router.push({ name: "HomeGoodsdetail", query: { goods_id: id } });
    },
  },
};
</script>

<style scoped lang="scss">
.storeUser,
.time {
  font-size: 0.6rem;
}
.storeUser {
  color: #3c7c45;
}
.ui-goodslist-filter {
  background: white;
  width: auto;
  ul.filter-list {
    display: flex;
    width: auto;
    justify-content: space-around;
    align-content: center;
    align-items: center;
    border: 0;
    /*border-top: .045rem solid #E8EAED;*/
    /*border-bottom: .045rem solid #E8EAED;*/
    li {
      font-size: 0.7rem;
      color: #333;
      border-bottom: 0.1rem solid transparent;
      position: relative;
      flex-basis: 4.54rem;
      text-align: center;
      height: 1.9rem;
      padding: 0;
      line-height: 1.9rem;
      a {
        height: 1.9rem;
        display: inline-block;
      }
      img {
        height: 0.18rem;
        width: 0.36rem;
        vertical-align: middle;
      }
      .iconfont {
        display: inline-block;
      }
    }
    li.sortactive {
      border-bottom-color: $primaryColor;
      a {
        color: $primaryColor;
      }
      .iconfont {
        color: $primaryColor;
      }
      .iconfont.active {
        transform: rotate(180deg);
      }
    }
    li.sortnormal {
      border-bottom-color: transparent;
      a {
        color: #333;
      }
    }
    .arrow-icon {
      width: 0.54rem;
      height: 0.54rem;
    }
  }
  .sort-model {
    position: absolute;
    left: 0;
    width: 100%;
    z-index: 10;
    div {
      color: #333;
      padding: 0.68rem;
      font-size: 0.59rem;
      background-color: #fff;
      margin: 0;
      border-bottom: 0.045rem solid #e8eaed;
      cursor: pointer;
      display: flex;
      width: auto;
      justify-content: space-between;
      align-content: center;
      align-items: center;
      img {
        float: right;
        width: 0.7rem;
        height: 0.7rem;
      }
      &.active {
        color: $primaryColor;
      }
    }
  }
}
.ui-product-body {
  background: white;
  border-bottom: 0.045rem solid rgba(232, 234, 237, 1);
  .list {
    padding-top: 0.5rem;
    display: flex;
    width: auto;
    align-items: center;
    justify-content: space-between;
    margin: 0.5rem 0.45rem;
    position: relative;
    div.ui-image-wrapper {
      width: 5rem;
      height: 5rem;
      position: relative;
      display: flex;
      justify-content: center;
      align-content: center;
      align-items: center;
      flex-basis: 5rem;
      flex-shrink: 0;
      background-position: center center !important;
      background-size: 4.54rem 4.54rem;
      background-repeat: no-repeat;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;

      img.product-img {
        width: 5rem;
        height: 5rem;
        flex-basis: 5rem;
        flex-shrink: 0;
      }
      img.product-img[lazy="loading"] {
        width: 1.36rem;
        height: 1.36rem;
      }
      img.product-im[lazy="error"] {
        width: 1.36rem;
        height: 1.36rem;
      }
      img.product-img[lazy="loaded"] {
        width: 5rem;
        height: 5rem;
        flex-basis: 5rem;
        flex-shrink: 0;
        background: rgba(255, 255, 255, 1);
      }
      span {
        position: absolute;
        height: 0.9rem;
        background: rgba(243, 244, 245, 1);
        line-height: 0.9rem;
        text-align: center;
        font-size: 0.63rem;
        color: $primaryColor;
        width: 5rem;
        bottom: 0;
        left: 0;
      }
    }
    .flex-right {
      padding-left: 0.63rem;
      width: 100%;
      position: relative;
      .title {
        color: #333;
        font-size: 0.7rem;
        line-height: 1rem;
        height: 2rem;
        font-weight: normal;
        overflow: hidden;
        margin-bottom: 0.36rem;
        letter-spacing: 1px;
        &.clear-bottom {
          margin-bottom: 0;
        }
      }
      .product-header {
        margin-bottom: 0.2rem;
        display: flex;
        align-items: center;
      }
      .p-price {
        color: $primaryColor;
        font-size: 0.7rem;
      }
      .p-info {
        margin-bottom: 0.2rem;
        .platform_store_wrapper {
          width: 2rem;
          display: inline-block;
        }
        .platform_store {
          font-size: 0.7rem;
          color: $primaryColor;
          // border: .045rem solid $primaryColor;
          border-radius: 0.13rem;
          //   padding: 0 0.2rem;
        }
        .goods_salenum {
          font-size: 0.65rem;
          margin-left: 2rem;
          color: #999;
        }
      }
      .add-cart {
        background: $primaryColor;
        border-radius: 50%;
        text-align: center;
        position: absolute;
        right: 0.8rem;
        bottom: 0.2rem;
        width: 1.4rem;
        height: 1.4rem;
        line-height: 1.4rem;
        i {
          font-size: 0.8rem;
          color: #fff;
          display: block;
        }
      }
    }
  }
}

.filter-attribute {
  padding: 0.5rem;
}
.filter-attribute dl {
  width: 100%;
}
.filter-attribute dt {
  height: 1.2rem;
  width: 100%;
  overflow: hidden;
  font-size: 0.8rem;
  color: #333;
}
.filter-attribute dd {
}
.filter-attribute dd a {
  position: relative;
  display: inline-block;
  color: #666;
  font-size: 0.6rem;
  text-align: center;
  background-color: #f7f7f7;
  border-radius: 0.2rem;
  height: 1.5rem;
  line-height: 1.5rem;
  margin: 0.5rem 1.5%;
  width: 30%;
}
.filter-attribute dd a.selected {
  color: #e93b3d;
  background-color: #fdf0f0;
}
.filter-attribute dd a.selected::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 15px;
  height: 15px;
  border-radius: 0 0 2px 0;
  background: url("../../../assets/image/home/attribute_selected.png") no-repeat;
  background-size: 15px auto;
  overflow: hidden;
  z-index: 1;
}

// .container {
//   height: 100%;
//   display: flex;
//   position: relative;
//   flex-direction: column;
//   justify-content: flex-start;
//   align-items: stretch;
// }

// .header {
//   border-bottom: 1px solid #e8eaed;
// }

// .list-wrapper {
//   flex: 1;
//   display: flex;
//   flex-direction: column;
//   justify-content: flex-start;
//   align-items: stretch;

//   .browse-list {
//     background-color: #fff;
//     // border-bottom: 1px solid #e8eaed;
//     display: flex;
//     justify-content: space-between;
//     align-items: center;
//     padding: 0.55rem 0.75rem;

//     .right {
//       width: 2.5rem;
//     }

//     .info {
//       flex: 1;

//       .title {
//         display: flex;
//         flex-direction: column;
//         justify-content: space-between;
//         font-size: 0.7rem;
//         color: #333;
//         width: calc(100vw - 22vw - 1.5rem - 50px);
//         height: 22vw;
//         float: right;
//         margin-left: 10px;
//         letter-spacing: 1px;
//         div:nth-child(1) {
//           font-size: 0.7rem;
//           line-height: 1rem;
//         }
//         div:nth-child(2) {
//           font-size: 0.7rem;
//           color: #b5b5b5;
//           font-weight: bold;
//         }
//       }

//       .image {
//         width: 22vw;
//         height: 22vw;
//         flex-shrink: 0;
//         float: left;
//       }
//     }
//   }
// }

// 模拟弹框
.simulationAlert {
  position: fixed;
  top: 35vh;
  left: 5vw;
  z-index: 1100;
  width: 90vw;
  height: 160px;
  text-align: center;
  font-size: 0;
  background: #ffffff;

  .title {
    margin-top: 15px;
    font-size: 20px;
    color: #333;
  }
  .text {
    margin-top: 20px;
    font-size: 18px;
    color: #999;
  }
  .btn {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 1200;
    width: 100%;
    height: 40px;
    border-top: 1px solid #ddd;
  }
  .btn button {
    width: 50%;
    height: 40px;
    line-height: 40px;
    box-sizing: border-box;
    font-size: 16px;
    border: none;
    background-color: #ffffff;
  }
  .btnLeft {
    border-right: 1px solid #ddd !important;
  }
  .btnRight {
    color: #e93b3d;
  }
}

.baffle {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1003;
  width: 100vw;
  height: 100vh;
  background: #000;
  opacity: 0.5;
}
</style>
